home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Context / ContextMaintainer.cp < prev    next >
Text File  |  1997-06-28  |  1KB  |  61 lines

  1. // ContextMaintainer.cp
  2.  
  3. #ifndef ContextMaintainer_h
  4. #include "ContextMaintainer.h"
  5. #endif
  6. #ifndef Context_h
  7. #include "Context.h"
  8. #endif
  9. #ifndef ListLoop_h
  10. #include "ListLoop.h"
  11. #endif
  12. #ifndef ContextUser_h
  13. #include "ContextUser.h"
  14. #endif
  15.  
  16. ListOf<ContextMaintainer> ContextMaintainer::maintainers;
  17.  
  18. ContextMaintainer::ContextMaintainer()
  19.   : old( Context::Current() ),
  20.      link( this )
  21.   {
  22.     maintainers.Add( link, afterEnd );
  23.   }
  24.  
  25. ContextMaintainer::ContextMaintainer( Context *toUse )
  26.   : old( Context::Current() ),
  27.      link( this )
  28.   {
  29.     maintainers.Add( link, afterEnd );
  30.     Context::Set( toUse );
  31.   }
  32.  
  33. ContextMaintainer::ContextMaintainer( const ContextUser& toUse )
  34.   : old( Context::Current() ),
  35.      link( this )
  36.   {
  37.     maintainers.Add( link, afterEnd );
  38.     toUse.SetContext();
  39.   }
  40.  
  41. ContextMaintainer::~ContextMaintainer()
  42.   {
  43.     Context::Set( old );
  44.   }
  45.  
  46. void ContextMaintainer::StopMaintaining( Context *toLose )
  47.   {
  48.     Context *previous = 0;
  49.     for ( ListLoop<ContextMaintainer> loop( maintainers );
  50.             loop.Unfinished();
  51.             loop++ )
  52.         if ( loop->old == toLose )
  53.             loop->old = previous;
  54.          else
  55.             previous = loop->old; 
  56.   }
  57.  
  58. #include "ListLink.cp"
  59. #include "ListOf.cp"
  60. #include "ListLoop.cp"
  61.